package com.vinyl.sound 
{
	import flash.events.Event;
	import com.vinyl.events.DataEvent;
	import com.vinyl.sound.SoundLoader
	import flash.events.EventDispatcher;
	
	/**
	 * ...
	 * @author 
	 */
	public class SoundProxy extends EventDispatcher
	{
		public var soundLoader:SoundLoader;
		public function SoundProxy( sl:SoundLoader ) 
		{
			soundLoader = sl;
			soundLoader.addEventListener( Event.COMPLETE, dataEventHandler );
		}
		
		//implements
		public function load():void
		{
			if( !soundLoader.initFlag )
			{
				trace( soundLoader.url + ": has been loaded" );
				soundLoader.load();
			}
			else
			{
				var data = soundLoader;
				dispatchEvent( new DataEvent( { data: data }, DataEvent.GETDATA ) ) ;
			}
		}
		
		public function get sound()
		{
			return soundLoader.sound;
		}
		
		private function dataEventHandler(event:Event):void
		{
			soundLoader.removeEventListener( Event.COMPLETE, dataEventHandler );
			var data = soundLoader;
			dispatchEvent( new DataEvent( { data: data }, DataEvent.GETDATA ) ) ;
		}
	}
}
